﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PatientInformationExtract.Components;
using PatientInformationExtract.Dictionary.Views;
using PatientInformationExtract.MainInterface.Views;
using System.Windows.Input;
using System.Windows;
using System.Windows.Controls.Primitives;

namespace PatientInformationExtract.Dictionary.ViewModels
{
    public class DictionaryManageViewModel : WindowViewModelBase
    {
        private ICommand _translationLearningDictionaryManageCommand;
        public ICommand TranslationLearningDictionaryManageCommand { get { return this._translationLearningDictionaryManageCommand; } }

        public delegate void DictionaryManageClosedHandler();
        public event DictionaryManageClosedHandler DictionaryManageClosedEvent;
        public delegate void DictionaryManageSavedHandler();
        public event DictionaryManageSavedHandler DictionaryManageSavedEvent;

        public DictionaryManageViewModel(WindowViewModelBase parent)
        {
            this._translationLearningDictionaryManageCommand = new Command(new Action<object>(this.TranslationLearningDictionaryManage));

            base._parent = parent;
            WindowInitialize();
            
        }

        protected override void WindowInitialize()
        {
            base.WindowInitialize();
            base._window = new DictionaryManage();
            base._window.DataContext = this;
            (base._window as DictionaryManage).DictionaryManageClosedEvent += new DictionaryManage.DictionaryManageClosedHandler(DictionaryManageViewModel_DictionaryManageClosedEvent);
            (base._window as DictionaryManage).DictionaryManageSavedEvent += new DictionaryManage.DictionaryManageSavedHandler(DictionaryManageViewModel_DictionaryManageSavedEvent);
            base.BindIsClosed();
        }

        private void DictionaryManageViewModel_DictionaryManageSavedEvent()
        {
            if (this.DictionaryManageSavedEvent != null)
            {
                this.DictionaryManageSavedEvent();
            }
        }

        private void DictionaryManageViewModel_DictionaryManageClosedEvent()
        {
            if (this.DictionaryManageClosedEvent != null)
            {
                this.DictionaryManageClosedEvent();
            }
        }

        private void TranslationLearningDictionaryManage(object o)
        {
            TranslationLearningDictionaryManageViewModel tldmVM = new TranslationLearningDictionaryManageViewModel(this, PanGu.Setting.PanGuSettings.Config.GetDictionaryPath() + "TranslationLearningDict.xml");
            tldmVM.Show();
        }

        public void AddNewWordOutSide(string word, string english)
        {
            (base._window as DictionaryManage).AddNewWordOutside(word, english);
        }

        public void Save()
        {
            (this._window as DictionaryManage).btnSave.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
        }
    }
}
